package com.seewo.dubbo.debugger.admin.config;

import lombok.extern.slf4j.Slf4j;
import net.sf.ehcache.CacheManager;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import java.util.Arrays;

/**
 * 缓存配置
 *
 * @author chenliangliang
 * @date 2018/7/27
 */
@Slf4j
@Configuration
//@EnableCaching
public class CacheConfig {

    @Bean
    public EhCacheCacheManager cacheManager(CacheManager cacheManager) {
        log.info("ehCacheCacheManager注入成功: " + Arrays.toString(cacheManager.getCacheNames()));
        return new EhCacheCacheManager(cacheManager);
    }

    @Bean
    public EhCacheManagerFactoryBean ehcache() {
        EhCacheManagerFactoryBean ehCacheManagerFactoryBean = new EhCacheManagerFactoryBean();
        ehCacheManagerFactoryBean.setConfigLocation(new ClassPathResource("config/ehcache.xml"));
        ehCacheManagerFactoryBean.setShared(true);
        return ehCacheManagerFactoryBean;
    }
}
